package com.jintoufs.service.message.impl;

import com.jintoufs.dao.QueryFilters;
import com.jintoufs.dao.category.CategoryMapper;
import com.jintoufs.dao.sys.MessageDAO;
import com.jintoufs.domain.sys.Message;
import com.jintoufs.logAnnotation.SystemServiceLog;
import com.jintoufs.service.message.MessageService;
import com.jintoufs.util.valid.ValidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDAO messageDAO;

    @Override
    public void deleteByPrimaryKey(Integer id) {
         messageDAO.delete(id);
    }

    @Override
    public int insert(Message record) {
        return messageDAO.insert(record);
    }


    @Override
    public int updateByPrimaryKey(Message record) {
        return messageDAO.update(record);
    }

    @Override
    public List<Message> queryByParams(Map map) {
        return messageDAO.getByParams(map);
    }



    @Override
    public Map<String, Object> save(Message message) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            if (ValidUtil.isEmpty(message.getId())) {
                messageDAO.insertSelective(message);
                result.put("msg", "新增成功");
            } else {
                messageDAO.updateByPrimaryKeySelective(message);
                result.put("msg", "更新成功");
            }
            result.put("status", "OK");
            return result;
        } catch (Exception e) {
            result.put("msg", "操作失败");
            result.put("status", "ERROR");
            return result;
        }
    }

    @Override
    @SystemServiceLog(description = "删除酒店")
    public void delete(Integer id) {

            messageDAO.deleteByPrimaryKey(id);

    }

    @Override
    public List<Map<String, Object>> findByMessage(Map<String, Object> params) {
        return messageDAO.findByMessage(params);
    }

    @Override
    public List<Map<String,Object>> getByFilter(QueryFilters filters) {
        List<Map<String,Object>> result = messageDAO.getByFilter(filters);
        return result;
    }

    @Override
    public Map<String,Object> getById(Integer id) {
        return messageDAO.queryByPrimaryKey(id);
    }

    @Override
    public Map<String, Object> next(Integer id) {
        return messageDAO.next(id);
    }

    @Override
    public Map<String, Object> prev(Integer id) {
        return messageDAO.prev(id);
    }
}
